home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / ab20 / unarced / graphics / betterthanjpeg / compress.rexx < prev    next >
OS/2 REXX Batch file  |  1995-03-17  |  7KB  |  197 lines

  1. /************************/
  2. /** REXX:COMPRESS.REXX **/
  3. /************************/
  4. /*    BY RICK TILLERY   */
  5. /************************/
  6.  
  7. /* ------------------------------------ */
  8. /* | THIS SCRIPT RUNS WITH ADPRO 2.0. | */
  9. /* ------------------------------------ */
  10.  
  11. /* Through some experimentation with ADPro, LZ and GIF compression, I've */
  12. /* COME UP WITH THIS SCRIPT.  JPEG IMAGE COMPRESSION IS VERY NICE FOR    */
  13. /* come up with this script for the compression of 24 bit images.  JPEG  */
  14. /* image compression is VERY nice for rather complicated images, (such   */
  15. /* as complex ray-traces, digitized pics, and scans) where it's losses   */
  16. /* are not readily apparent.  But for the majority of ray-traced and     */
  17. /* hand-drawn pictures, a passable JPEG compressed file is almost as     */
  18. /* large as (or larger in a very few cases) the original IFF 24 file.    */
  19.  
  20. /* (NOTE: DCTV and HAM-E users will not notice the degradation until a   */
  21. /*  much lower Q rating is used.  Toaster, FireCracker24, Rembrant,      */
  22. /* Harlequin, IV24, and other full 24 bit board owners will be very      */
  23. /* thankful if you distribute the original 24 bit data, and let their    */
  24. /* particular device degrade it as it must.)                             */
  25.  
  26. /* When I separated out the red, green and blue components of some 24    */
  27. /* bit pics and then created three separate GIF files from them, I       */
  28. /* noticed that the resulting GIF files were extremely small.  Earlier,  */
  29. /* I had purported that taking the raw sculpt files (red, green and      */
  30. /* blue) and compressing them with LZ (or LHArc) was the best non-lossy  */
  31. /* method of transferring 24 bit pics.  This was indeed smaller than the */
  32. /* IFF 24 files compressed or not.  This GIF method usually results in   */
  33. /* files at least half as large as that!  So, until I can author my own  */
  34. /* IFF LZW format (along with suitable encode/decode programs), I offer  */
  35. /* this script and its companion for lossless 24 bit image compression.  */
  36. /* Give it a try, and see what you think.                                */
  37.  
  38. /* Instructions:  1. Move input file(s) to a HD partition with at least */
  39. /*                   WIDTH x HEIGHT x 3 x 2 free bytes (i.e. 768 x 480  */
  40. /*                   x 3 x 2 = 2,211,840 bytes)                         */
  41. /*                2. Run ADPro 2.0                                      */
  42. /*                3. Run this script                                    */
  43. /*                4. Use ADPro requester to give name of input file     */
  44. /*                5. WAIT - this script with produce an archive of the  */
  45. /*                   three GIF files that you can upload                */
  46.  
  47. /* Portal:  RTillery  (RTillery@cup.portal.com) */
  48.  
  49.  
  50.  
  51. /* Open port to ADPro - it must be running first */
  52.    ADDRESS "ADPro"
  53.    
  54. /* Turn on results flag to get data FROM ADPro... */
  55. /* ...and set loader/saver formats */
  56.    OPTIONS RESULTS
  57.    LFORMAT "UNIVERSAL"
  58.    SFORMAT "SCULPT"
  59.    
  60. /* Ask user for input file */
  61.    LOAD '"' || '"'
  62.  
  63. /* Get name of input file from ADPro for script manipulation */
  64.    LAST_LOADED_IMAGE
  65.    FILE = ADPRO_RESULT
  66.    
  67. /* First of the three Sculpt format raw files */
  68.    OUTFILE = FILE||'.red'
  69.    
  70. /* Save the raw image info in three separate red, green and blue files */
  71.    SAVE OUTFILE RAW
  72.  
  73. /* THE FOLLOWING CODE IS FOR COMPARISON OF LZH COMPRESSION OF THE RAW */
  74. /* SCULPT FILES TO THEIR GIF EQUIVALENTS.  TO DO THIS COMPARISON, */
  75. /* DELETE THE COMMENT SYMBOLS (/* */) HERE AND AT THE END OF THIS */
  76. /* SCRIPT. */
  77.  
  78. /*
  79.    ADPRO_TO_BACK
  80.  
  81. /* Access DOS */
  82.    ADDRESS "COMMAND"
  83.    
  84. /* Clear CLI script was called from */
  85.    'ECHO' '"*E[0;0H*E[J"'
  86. /* Archive three raw image files */
  87.    'LZ' A FILE||'.SCULPT.LZH' FILE||'.#?'
  88. /* NOTE:  Don't forget that the raw files have no image size info, so if */
  89. /*        for some reason you want to send the above archive somewhere,  */
  90. /*        you must add a file letting the recipient know what the        */
  91. /*        image's dimensions are.                                        */
  92.    
  93.    ADDRESS "ADPro"
  94.    
  95.    ADPRO_TO_FRONT
  96. */
  97.    
  98. /* Get Width of loaded image from ADPro */
  99.    XSIZE
  100.    WIDTH = ADPRO_RESULT
  101.    
  102. /* Get Height of loaded image from ADPro */
  103.    YSIZE
  104.    HEIGHT = ADPRO_RESULT
  105.    
  106. /* Create blank image same size as input image */
  107.    LFORMAT "BACKDROP"
  108.    LOAD "dummy" WIDTH HEIGHT GRAY
  109.    
  110. /* And save it */   
  111.    SAVE FILE||'.GRAY1' RAW
  112.  
  113. /* Get ready to read in raw files */
  114.    LFORMAT 'SCULPT'
  115.    
  116. /* Access to DOS */
  117.    ADDRESS "COMMAND"
  118.    
  119. /* We need two copies of that blank image because ADPro requires there */
  120. /* be three separate files for the Sculpt loader from AREXX            */
  121.    'COPY' FILE||'.GRAY1' FILE||'.GRAY2'
  122. /* Replace Green file with blank file */
  123.    'RENAME' FILE||'.GRN' FILE||'.GOLD'
  124.    'RENAME' FILE||.'GRAY1' FILE||.'GRN'
  125. /* Replace Blue file with blank file */
  126.    'RENAME' FILE||'.BLU' FILE||'.BOLD'
  127.    'RENAME' FILE||'.GRAY2' FILE||'.BLU'
  128.  
  129.    ADDRESS "ADPro"
  130.    
  131. /* Get raw data but since Green and Blue are blank, it's only Red data */
  132.    LOAD OUTFILE WIDTH HEIGHT COLOR
  133.    
  134. /* Create 256 color rendition for GIF image */
  135.    RENDER_TYPE '256'
  136.    EXECUTE
  137.    
  138. /* Save GIF file */
  139.    SFORMAT 'GIF'
  140.    SAVE FILE||.'RED.GIF' IMAGE
  141.  
  142. /***********************************************************************/
  143. /* From here on out, we do the same thing as above with the Green and  */
  144. /* Blue data                                                           */
  145. /***********************************************************************/
  146.  
  147.    ADDRESS "COMMAND"
  148.    
  149.    'RENAME' FILE||'.RED' FILE||'.ROLD'
  150.    'RENAME' FILE||'.GRN' FILE||'.RED'
  151.    'RENAME' FILE||'.GOLD' FILE||'.GRN'
  152.    
  153.    ADDRESS "ADPro"
  154.    
  155.    LOAD OUTFILE WIDTH HEIGHT COLOR
  156.    
  157.    RENDER_TYPE '256'
  158.    EXECUTE
  159.    
  160.    SAVE FILE||.'GREEN.GIF' IMAGE
  161.  
  162.    ADDRESS "COMMAND"
  163.    
  164.    'RENAME' FILE||'.GRN' FILE||'.GOLD'
  165.    'RENAME' FILE||'.BLU' FILE||'.GRN'
  166.    'RENAME' FILE||'.BOLD' FILE||'.BLU'
  167.    
  168.    ADDRESS "ADPro"
  169.    
  170.    LOAD OUTFILE WIDTH HEIGHT COLOR
  171.    
  172.    RENDER_TYPE '256'
  173.    EXECUTE
  174.    
  175.    SAVE FILE||.'BLUE.GIF' IMAGE
  176.    
  177.    ADPRO_TO_BACK
  178.    
  179.    ADDRESS "COMMAND"
  180.    
  181. /* Get rid of superfluous raw files */
  182.    'DELETE' '>NIL:' FILE||'.(RED|GRN|BLU|ROLD|GOLD)'
  183.    
  184. /* Put three GIF files into archive WITHOUT trying to compress */
  185.    'LZ' '-z' A FILE||'.LZH' FILE||'#?GIF'
  186. /* Now get rid of GIF files */
  187.    'DELETE' '>NIL:' FILE||'*GIF'
  188.    
  189. /* THE FOLLOWING COMMAND GOES WITH THE ABOVE CODE FOR LZH TO GIF COMPARE */
  190.  
  191. /*
  192.    LIST FILE||'#?'
  193. */
  194.  
  195.  
  196.  
  197.